package com.dhj.streamTest;

import com.dhj.streamTest.entity.Author;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo3 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        authors.stream().filter(author -> author.getAge() > 10)
                .forEach(author -> System.out.println(author.getName() + "--" + author.getAge()));


        System.out.println("======================");


        Stream<Author> distinct = authors.stream().distinct();
        List<Author> collect = distinct.collect(Collectors.toList());

        collect.forEach(author -> System.out.println(author.getName() + "--" + author.getAge()));


        System.out.println("-----------------------------------");


        authors.stream().filter(new Predicate<Author>() {
            @Override
            public boolean test(Author author) {
                return author.getAge() < 60;
            }
        }).forEach(new Consumer<Author>() {
            @Override
            public void accept(Author author) {
                System.out.println(author.getName() + "--" + author.getAge());
            }
        });

    }
}
